package master

import (
	"encoding/json"
	"io/ioutil"
)

//程序配置
type Config struct {
	ApiPort          int      `json:"ApiPort"`
	ApiReadTimeout   int      `json:"ApiReadTimeout"`
	ApiWriteTimeout  int      `json:"ApiWriteTimeout"`
	ZKEndPoint       []string `json:"ZKEndPoint"`
	ZKConnectTimeout int      `json:"ZKConnectTimeout"`
	WebRoot          string   `json:"WebRoot"`
	DbUrl            string   `json:"DbUrl"`
	DbConnectTimeout int      `json:"DbConnectTimeout"`
	DbType           string   `json:"DbType"`
	DbName           string   `json:"DbName"`
	TableName        string   `json:"TableName"`
}

//单例模式
var (
	G_Config *Config
)

func InitConfig(filename string) (err error) {
	var (
		content []byte
		conf    Config
	)
	//读取文件
	if content, err = ioutil.ReadFile(filename); err != nil {
		return err
	}
	//json的反序列表
	if err = json.Unmarshal(content, &conf); err != nil {
		return err
	}
	G_Config = &conf
	return nil

}
